<?php
class ProductsettingModel extends Model {
	protected $autoCheckFields = false;
	/**
	 * 产品信息
	 *
	 * @param $proid
	 * @return
	 */
	public function getProduct( $proid ) {
		$proinfo = D ( "Product" )->where ( "id={$proid}" )->find ();
		$prosku = D ( "Productsku" )->where ( "proid={$proid}" )->order( "convert(prosku using gb2312)  ASC" )->select ();
		 
		foreach ( $prosku as $k=>$sku ) {
			$proinfo['skuinfo'][$k]['skuid'] = $sku['skuid'];
			$proinfo['skuinfo'][$k]['prosku'] = $sku['prosku'];
			$proinfo['skuinfo'][$k]['prolower'] = $sku['prolower'];
			$proinfo['skuinfo'][$k]['proweight'] = $sku['proweight'];
			
		}
		return $proinfo;
	}
	public function getProductList( $offset, $length, $skuorder = false ) {
		if( true == $skuorder ) {
			$order = "convert(prosku using gb2312)  ASC";
		}else {
			$order = "id DESC";
		}
		return D ( "Product" )->limit ( $offset . ',' . $length )->order ( $order )->select ();
	}
	public function getProductCount() {
		return D ( "Product" )->count ();
	}

	public function getInventoryList($fields='') {
		return D( "ProductView" )->field($fields)->order( "`prosku` ASC" )->select();
	}
}